﻿using System.Text;

namespace TPXSDK.NET.Mission.Instruction;

internal class InstWaitFmt : Tokenizer
{
    public InstWaitFmt(TokenizerAdmin admin)
    {
        Admin = admin;
        KeyName = "waitfmt";
        KeyValue = (byte)FlyCmdId.CMD_WAITFMT;
        Usage = "waitfmt";
        Description = @"Waits until all drone in formation is ready.";
    }

    public override bool Process()
    {
        var flyCmp = Admin?.Compiler; if (null == flyCmp) return false; if (null == flyCmp) return false;
        var tokens = flyCmp.GetLineTokens();
        if (tokens is not { Count: 1 })
        {
            flyCmp.ErrorMsg = $"{KeyName} Invalid Usage";
            return false;
        }
        var cmd = new FlyCmdItem
        {
            Id = (byte)KeyValue,
            LineNum = tokens[0].Row
        };
        flyCmp.CmdList.Add(cmd);

        return true;
    }

    public override void Reverse(FlyCmdItem cmd, StringBuilder sb)
    {
        sb.AppendLine($"{KeyName}");
    }
}
